package com.kqb.controller;

import com.kqb.common.controller.base.BaseController;
import com.kqb.common.domain.AjaxResult;
import com.kqb.pojo.Dict;
import com.kqb.service.IDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 杉果树皮
 * @date 2025/2/23 17:27
 * @description:
 */
@RestController
@RequestMapping("/api")
@Api(tags = "分类字典")
public class DictController extends BaseController {
    @Autowired
    private IDictService iDictService;

    @PostMapping("/dict")
    @ApiOperation("添加分类")
    public AjaxResult save(@RequestBody Dict dict) {
        return iDictService.save(dict);
    }

    @GetMapping("/dict/all")
    @ApiOperation("查询所有分类")
    public AjaxResult selectAll() {
        return iDictService.selectAll();
    }

    @DeleteMapping("/dict/{id}")
    @ApiOperation("删除字典")
    public AjaxResult deleteById(@PathVariable("id") Integer id) {
        return iDictService.deleteById(id);
    }

    @PutMapping("/dict")
    @ApiOperation("修改字典")
    public AjaxResult update(@RequestBody Dict dict) {
        return iDictService.update(dict);
    }

    @GetMapping("/dict/{code}")
    @ApiOperation("查询分类根据编码")
    public AjaxResult selectByCode(@PathVariable("code") String code) {
        return iDictService.selectByCode(code);
    }

}
